//
//  FJKWebViewController.m
//  FangGeek
//
//  Created by FangGeek on 2016/10/31.
//  Copyright © 2016年 FangGeek. All rights reserved.
//

#import "FJKWebViewController.h"

@interface FJKWebViewController ()<FJKWebViewDelegate>

@end

@implementation FJKWebViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.edgesForExtendedLayout = UIRectEdgeNone;

    [self buildUI];
    
    [self buildNav];
    
    [self loadURL];
    
}

#pragma mark - Private Method

- (void)buildUI
{
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
 
    self.navigationController.view.backgroundColor = [UIColor whiteColor];

    self.webView = [[FJKWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    self.webView.progressView.top += SA_CONTENT_START_Y;
    [self.view addSubview:self.webView];
}

- (void)buildNav
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_arrow"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
}

- (void)loadURL
{
    //请求URL上拼接agent_id参数给H5
    
    NSString *appendUserIDStr =_urlString;
    NSURL *urlString = [NSURL URLWithString:appendUserIDStr];
    [self.webView loadRequest:[NSURLRequest requestWithURL:urlString]];
    self.webView.delegate = self;
}


- (void)closeWebView
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Action

- (void)back
{
     self.navigationItem.rightBarButtonItem = nil;
    [self backNative];
}

//点击返回的方法
- (void)backNative
{
    //判断是否有上一层H5页面
    if ([self.webView.wkWebView canGoBack])
    {
        //如果有则返回
        [self.webView.wkWebView goBack];
        //同时设置返回按钮和关闭按钮为导航栏左边的按钮
       
    }
    else
    {
        [self closeWebView];
    }
}

@end
